

<template>
	<view class="s-back subscribe">
        <view class="flex">
			<view class="text1" style="visibility: hidden;">
				<uni-icons type="back" size="25" @click="goBack" color="#fff"></uni-icons>
			
			</view>
			<view class="flex1">登录</view>
			<view class="right" style="color:transparent">恢复订阅</view>		
        </view>

		<view class="inp1" style="margin-top:120rpx">

			<input class="inpt" placeholder="用户名/手机号/邮箱" 
							confirm-type="send" style="font-size: 30rpx;" 
							cursor-spacing="40"
							  
							ref="inputRef" v-model="username" :adjust-position="false"/> 
							
						</view>

						<view class="inp1">

						<input class="inpt" placeholder="请输入密码" 
					
							confirm-type="send" style="font-size: 30rpx;width: 100%;" 
							cursor-spacing="40"
							:password="!showPassword"
							ref="inputRef" v-model="password" :adjust-position="false"/> 
		
							<uni-icons v-if="showPassword" style="margin-left: 14px;" type="eye" size="20" @click="showPassword=false" color="#999"></uni-icons>

<uni-icons v-else style="margin-left: 14px;" type="eye-slash" size="20" @click="showPassword=true" color="#999"></uni-icons>



						</view>
		<view class="btn" @click="login">登录</view>
		
		<view style="display: flex;justify-content: space-between;align-items: center;">
			<view @click="jumpRegister" class="left">
			注册
		</view>
		<!-- <view @click="jumpWechat" class="left">
			微信登录
		</view> -->
		</view>

		<view v-if="isShowPcLogin==1">
			<view class="login-l1">
				<view class="lin1"></view>
				<view class="txt1">其他登录方式</view>
				<view class="lin1"></view>
			</view>

			<view class="login-l2">
				<view class="wechat" @tap="pcwechatLogin">
					<uni-icons type="weixin" size="50"  color="#fff"></uni-icons>

				</view>
				

				
			</view>
		</view>


			
		<u-popup :mask-close-able="false" mode="center" border-radius="0" v-model="isShowPop">
			<u-image :src="form.code" width='500' height="500"></u-image>
    </u-popup>
		
		
	
	</view>
</template>

<script>

import { isMobile } from '@/utils';

	export default {
		name:"subscribe",
    components:{},
		data() {
			return {
				showPassword:false,
				username:'',
				password:'',
				isShowPcLogin:'',
				form:{},
				isShowPop:false,
				timer:null,
				
            }
		},
		onLoad() {
			
				this.isShowPcLogin = uni.getStorageSync('isShowPcLogin')&&!isMobile()
			if(this.isShowPcLogin) this.getData()
			},
		mounted() {
			
		},
		beforeDestroy() {
			clearInterval(this.timer)
						this.timer = null
		},
		
		computed:{
			
		},
		methods: {
			async getData(){
				const r = await this.$u.api.userPcQrcodeLogin()
				if(r){
					this.form = r.data
				}
			},
			pcwechatLogin(){
				this.isShowPop = true
				this.timer = setInterval(async()=>{
					const r = await this.$u.api.userPcQrcodeLoginStatus(
						{
							random:this.form.random
						}
					)
					if(r){
						clearInterval(this.timer)
						this.timer = null
						this.afterLogin(r)
					}

				},5000)
			},
			goBack(){
				uni.navigateBack({
					 delta: 1
				});
			},
			jumpWechat(){
				uni.navigateTo({
					url:'/pages/wechatLogin/wechatLogin'
				})
			},
			jumpRegister(){
				uni.navigateTo({
					url:'/pages/register/register'
				})
			},
			async login(){
				const r = await this.$u.api.userLogin({
					mobile:this.username,
					password:this.password
				})
				if(r){
					this.afterLogin(r)
				}
			},
			async afterLogin(r){
				this.$u.toast('登录成功');
					this.getPageData()
                  	this.getRemindData()
					uni.setStorageSync('h5Token',r.data.token)
					await this.getUserId()
					uni.$emit('updateDataMy')
					setTimeout(()=>{
					
						uni.switchTab({
							url:'/pages/index/index?isMiniprogram='+uni.getStorageSync('isMiniprogram')
						})
					},1000)
			},
			async getPageData(){
				const r = await this.$u.api.configTitle()
				if(r){
					uni.setStorageSync('pageTitle',r.data.title)
				}
			},
			async getRemindData(){
	// 			"zdz_remind": "查出",
    // "welcome": "欢迎"
				const r = await this.$u.api.configRemind()
				if(r){
					uni.setStorageSync('welcome',r.data.welcome)
				}
			},
			async getUserId(){
				let r = await this.$u.api.userInfo()
				if (r) {
					localStorage.setItem('userId',r.data.id)
					localStorage.setItem('isJumpMini','1')
							}
						}
		}
	}
</script>

<style lang="scss" scoped>
.subscribe{
	.flex{
		padding:24rpx;
		display: flex;
		color: #fff;
	}
	.text1{
		width: 130rpx;
	}
	.flex1{
		display: flex;
		justify-content: center;
		flex: 1;
		font-size: 36rpx;
	}
	.right{
		color: #828694;
		font-size: 32rpx;
	}
	.inp1{
			
			padding: 16rpx 20rpx;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			flex-direction: row;
			margin:40rpx;
			border-radius: 60rpx;
			border: 1px solid #78A4A1;

			.inpt{
				margin-left: 20rpx;
				color: #fff;
			}
		}
		.btn{

			border-radius: 50rpx;
			background-image: linear-gradient(to top, #7CD887,#75CCD1);
			padding:26rpx 40rpx;
			color:#000;
			font-size: 30rpx;
			font-weight: 500;
			text-align: center;
			margin:40rpx;
		}
		.left{
			margin:40rpx 60rpx;
			color: #797979;
		}
	
	
}
@media screen and (min-width: 700px) {
	.btn{
		width: 660px;
	}
	
}
.login-l1{
	padding: 20px;
	display: flex;
	align-items: center;
	color: #999;
	.lin1{
		flex: 1;
		background: #333;
		height: 1px;

	}
	.txt1{
		flex: 0;
		white-space: nowrap;
		margin:0 14px;

	}
}
.login-l2{
	padding: 20px 0;
	display: flex;
	justify-content: center;
	.wechat{
	background: #5DA360;
	
	border-radius: 50%;
	display: inline-block;
	padding: 10px;
}
}

</style>
